﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TimeTravel.Components;
using TimeTravel.Extentions;
using TimeTravel.IData;
using TimeTravel.DataProvider;
using TimeTravel.IServices;

namespace TimeTravel.Services
{
    public class AnnouncementService : IAnnouncementService
    {
        private static readonly IAnnouncementData DataProvider = DataAccess.CreateDataInstance<IAnnouncementData>();

        #region Implementation of IServiceBase<AnnouncementInfo>

        /// <summary>
        /// 添加记录
        /// </summary>
        public int Add(AnnouncementInfo announcement)
        {
            return DataProvider.Add(announcement);
        }

        /// <summary>
        /// 删除记录
        /// </summary>
        /// <param name="id"></param>
        public void Delete(int id)
        {
            if (id != 0)
            {
                DataProvider.Delete(id);
            }
        }

        /// <summary>
        /// 更新记录
        /// </summary>
        /// <param name="announcement"></param>
        public void Update(AnnouncementInfo announcement)
        {
            if (announcement != null && announcement.ID != 0)
            {
                DataProvider.Update(announcement);
            }
        }

        /// <summary>
        /// 获取所有
        /// </summary>
        /// <returns></returns>
        public IList<AnnouncementInfo> GetAll()
        {
            return DataProvider.GetAll();
        }

        /// <summary>
        /// 根据条件获取
        /// </summary>
        /// <param name="query"></param>
        /// <returns></returns>
        public RecordSet<AnnouncementInfo> GetBySearch(PageQueryInfo query)
        {
            if (query == null)
            {
                return new RecordSet<AnnouncementInfo>();
            }
            return DataProvider.GetBySearch(query);
        }

        /// <summary>
        /// 获取详细信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public AnnouncementInfo GetOne(int id)
        {
            if (id == 0)
            {
                return null;
            }
            return DataProvider.GetOne(id);
        }

        /// <summary>
        /// 获取总数
        /// </summary>
        /// <returns></returns>
        public int GetTotalCount()
        {
            return DataProvider.GetTotalCount();
        }

        /// <summary>
        /// 更新公告查看次数
        /// </summary>
        /// <param name="id"></param>
        public void UpdateClickCount(int id)
        {
            if (id != 0)
            {
                DataProvider.UpdateClickCount(id);
            }
        }

        #endregion
    }
}
